/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.com.remiseria.dao;

import ar.com.remiseria.entities.Domicilio;
import ar.com.remiseria.utils.HibernateUtils;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author mcvalls
 */
public class DomicilioDAO extends GenericDAO{

    public Domicilio getDomicilioByTodosLosDatos(Domicilio domicilio) throws HibernateException{
        Session session = HibernateUtils.getSessionFactory().getCurrentSession();
        Transaction tx = session.beginTransaction();
        
        Criteria criteria = session.createCriteria(Domicilio.class);
        criteria.add(Restrictions.eq("calle", domicilio.getCalle()));
        criteria.add(Restrictions.eq("numero", domicilio.getNumero()));
//        criteria.add(Restrictions.eq("piso", domicilio.getPiso()));
        criteria.add(Restrictions.eq("departamento", domicilio.getDepartamento()));
        criteria.add(Restrictions.eq("codigoPostal", domicilio.getCodigoPostal()));
        criteria.add(Restrictions.eq("localidad", domicilio.getLocalidad()));
        criteria.add(Restrictions.eq("provincia", domicilio.getProvincia()));
        
        Domicilio dom = (Domicilio)criteria.uniqueResult();
        
        return dom;
    }
    
}
